Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Scripting Additions Guide /
Chapter 3 - Writing Scripting Additions


Using Records for Scripting Addition Reply Values

Some scripting additions return more than one piece of data in their replies. If a scripting addition returns a list, it can refer to the elements of the list by index. But if a scripting addition returns a record with named fields, it cannot refer to the items in the record by their names, because although an 'aete' resource allows you to specify the type of a return value, it does not provide any additional information about it, such as the names of its fields if it is a record.

If you need that additional information, you can create a new class that has properties for each of the fields in the record, and you can then declare the return type of the reply to be the ID of this new class.

Listing 3-2 shows an 'aete' code excerpt that defines a class with the ID 'hack'. This code is placed in the return type field of the event's reply. The property IDs are the keywords for the record's fields.

Listing 3-2 Classes array for a scripting addition that returns a record

{  /* array Classes: 1 elements */
   /* [1] */
   "my record names",
   'hack',
   "A demo class used for record labels", 
   {  /* array Properties: 2 elements */
      /* [1] */
      "button returned",
      'rone',
      ' hack',
      "The button returned",
      reserved,
      singleItem,
      notEnumerated,
      readOnly,
      reserved, reserved, reserved, reserved, reserved, reserved, 
      reserved, reserved, reserved, reserved, reserved, reserved,
      /* [2] */
      "text returned",
      'rtwo',
      'hack',
      "The text returned",
      reserved,
      singleItem,
      notEnumerated,
      readOnly,
      reserved, reserved, reserved, reserved, reserved, reserved,
      reserved, reserved, reserved, reserved, reserved, reserved
   },
},
For an example of this technique in action, see the reply returned by the Display Dialog scripting addition.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
18 DEC 1996